<template lang="pug">
.detail
  .detail-header
    .iconfont.icon-back(@click="$router.back()")
    .detail-header-title 案例详情
  .detail-content
    .detail-section
      .section-title
        span 基本信息
      .section-body.detail-spec
        .spec-col
          .spec-row
            .spec-row-label 案例名称
            .spec-row-value {{detail.Information.materialCaseInf.projectName}}
          .spec-row
            .spec-row-label 所属业态
            .spec-row-value.flex
              .spec-row-tag(v-for="item in detail.Information.style") {{item.styleName}}
        .spec-col
          .spec-row
            .spec-row-label 项目地址
            .spec-row-value {{detail.Information.materialCaseInf.country}}{{detail.Information.materialCaseInf.provinceVal ? '-' : ''}}{{detail.Information.materialCaseInf.provinceVal}}{{detail.Information.materialCaseInf.cityVal ? '-' : ''}}{{detail.Information.materialCaseInf.cityVal}}{{detail.Information.materialCaseInf.detailAddress ? '-' : ''}}{{detail.Information.materialCaseInf.detailAddress}}
          .spec-row
            .spec-row-label 项目时间
            .spec-row-value {{detail.Information.materialCaseInf.caseDate}}
  .detail-content
    .detail-section
      .section-title
        span 案例详情
        .section-title-line
      .section-body.detail-body
        .detail-body-content
          .detail-carousel
            el-carousel(height="530px", :autoplay="false" @change="changeCarousel")
              el-carousel-item(v-for="item, index in detail.picture", :key="index")
                .detail-carousel-img(:style="item.picUrl | filterUrl")
          .detail-info-content(v-html="detail.Information.materialCaseInf.projectDetail")
        .detail-body-materials
          .detail-body-materials-title 该页面包含材料
          .case-list
            .case-item(v-for="item in caseList")
              .case-item-body
                .case-item-img(:style="item.materialImg | filterUrl")
                  .case-item-tag {{item.country}}
                .case-item-bd
                  .case-item-name {{item.materialName}}
                  .case-item-price ¥{{item.lowPrice}}-{{item.highPrice}}
                  .case-item-company {{item.companyName}}
</template>

<script>
import { getCaseDetail } from 'api'
export default {
  name: 'caseDetail',
  data () {
    return {
      detail: {
        Information: {
          materialCaseInf: {
            projectName: '',
            caseDate: '',
            style: [],
          }
        },
        picture: []
      },
      defaultIndex: 0,
      caseList: []
    }
  },
  methods: {
    changeCarousel (index) {
      this.defaultIndex = index
      this.caseList = this.detail.picture[this.defaultIndex].materialsList
    },
    async getDetail () {
      try {
        const { ResultSet } = await this.$axios.post(getCaseDetail, { materialCaseId: this.$route.params.id })
        this.detail = ResultSet.userData
        this.caseList = this.detail.picture[this.defaultIndex].materialsList
      } catch (err) {
        console.log(err)
        this.$message.error(err.message || err.ResultSet.errors)
      }
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      vm.getDetail()
    })
  }
} 
</script>

<style lang="scss" scoped>
.detail {
  width: 100%;
  min-height: 100%;
  background: #fff;
  border: 1px solid #F3F3F4;
  box-sizing: border-box;
  box-shadow: 0px 4px 0px #F3F3F4;
  border-radius: 10px;
}
.detail-header {
  display: flex;
  align-items: center;
  padding: 23px 40px;
  border-bottom: 1px solid #EDEDED;
  .iconfont {
    font-size: 24px;
    color: #B2B4C7;
    margin-right: 12px;
    cursor: pointer;
  }
  .detail-header-title {
    font-weight: bold;
    font-size: 18px;
    line-height: 26px;
    color: #3E4373;
  }
}
.detail-content {
  padding: 40px;
}
.detail-section {
  margin-bottom: 40px;
}
.section-title {
  position: relative;
  font-weight: bold;
  font-size: 18px;
  line-height: 26px;
  color: #B2B4C7;
  margin-bottom: 16px;
  &:before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 10px;
    background: #B2B4C7;
    border-radius: 8px;
    z-index: 2;
  }
  span {
    position: relative;
    z-index: 1;
    display: inline-block;
    background: #fff;
    padding: 0 8px 0 12px;
  }
  .section-title-line {
    width: 100%;
    height: 1px;
    background: #EDEDED;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }
}
.detail-spec {
  width: 100%;
  background: #F6F6F9;
  border-radius: 6px;
  padding: 24px;
}
.spec-col {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
  &:last-child {
    margin-bottom: 0;
  }
  .spec-row {
    width: 33.33%;
    .spec-row-label {
      font-size: 14px;
      line-height: 22px;
      color: #8B8EAB;
    }
    .spec-row-value {
      font-size: 16px;
      line-height: 24px;
      color: #3E4373;
      margin-top: 4px;
      display: flex;
      align-items: center;
    }
    .spec-row-tag {
      padding: 1px 10px;
      font-size: 14px;
      line-height: 22px;
      color: #3E4373;
      background: rgba(134, 118, 255, 0.1);
      border-radius: 6px;
      margin-right: 8px;
    }
  }
}
.detail-body {
  display: flex;
}
.detail-body-content {
  width: 834px;
}
.detail-carousel-img {
  width: 100%;
  height: 100%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  border-radius: 12px;
}
.detail-info-content {
  width: 724px;
  margin-top: 40px;
}
.detail-body-materials {
  flex: 1;
  padding-left: 100px;
  .detail-body-materials-title {
    padding: 0 20px;
    font-weight: bold;
    font-size: 18px;
    line-height: 26px;
    color: #3E4373;
  }
}
.case-list {
  margin-top: 16px;
  padding: 24px 12px;
  width: 100%;
  min-width: 600px;
  height: 669px;
  max-height: 669px;
  overflow: overlay;
  background: #F6F6F9;
  border-radius: 10px;
}
.case-item {
  width: 50%;
  padding: 0 12px;
  margin-bottom: 24px;
  .case-item-body {
    width: 100%;
    background: #FFFFFF;
    border-radius: 6px;
    .case-item-img {
      position: relative;
      width: 100%;
      height: 180px;
      border-radius: 6px 6px 0 0;
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
      .case-item-tag {
        position: absolute;
        left: 12.5px;
        bottom: 4px;
        padding: 2px 8px;
        background: #FF708B;
        border-radius: 2px;
        line-height: 22px;
        font-size: 12px;
        color: #FFFFFF;
      }
    }
    .case-item-bd {
      padding: 8px;
    }
    .case-item-name {
      font-weight: bold;
      font-size: 14px;
      line-height: 22px;
      color: #3E4373;
    }
    .case-item-price {
      margin-top: 2px;
      font-weight: bold;
      font-size: 14px;
      line-height: 22px;
      color: #FF2E42;
    }
    .case-item-company {
      margin-top: 2px;
      font-size: 12px;
      line-height: 20px;
      color: #8B8EAB;
    }
  }
}
</style>
